/**
 * 
 */
package tp.pr5.instructions;

import tp.pr5.NavigationModule;
import tp.pr5.RobotEngine;
import tp.pr5.instructions.exceptions.InstructionExecutionException;
import tp.pr5.instructions.exceptions.WrongInstructionFormatException;
import tp.pr5.items.ItemContainer;

/**
 * This Instruction shows the description of the current place and the items in it. This Instruction works if the user writes RADAR
 *
 */
public class RadarInstruction implements Instruction {
	private NavigationModule navigation;
	
	/**
	 * It builds a default RadarInstruction
	 */
	public RadarInstruction()
	{}
	

	@Override
	/**
	 * Parses the String returning an instance of RadarInstruction or throwing a WrongInstructionFormatException()
	 * @param cad - text String to parse
	 * @return Instruction Reference to an instance of RadarInstruction
	 * @throws WrongInstructionFormatException - When the String is not RADAR
	 */
	public Instruction parse(String cad) throws WrongInstructionFormatException 
	{
		if (cad.equalsIgnoreCase("RADAR"))
		{
			return new RadarInstruction();
		}
		else
			throw new WrongInstructionFormatException(cad);
	}

	@Override
    /**
     * Returns a description of the Instruction syntax. The string does not end with the line separator. It is up to the caller adding it before printing.
     * @return The Instruction's syntax.
     */
	public String getHelp() {
		return "RADAR";
	}

	@Override
	/**
	 * Set the execution context. The method receives the entire engine (engine, navigation and the robot container) even though the actual implementation of execute() may not require it.
	 * @param engine - The robot engine
	 * @param navigation - The information about the game, i.e., the places, current direction and current heading to navigate
	 * @param robotContainer - The inventory of the robot
	 */
	public void configureContext(RobotEngine engine, NavigationModule navigation, ItemContainer robotContainer) {
		this.navigation = navigation;
	}

	@Override
	/**
	 * Shows the current place description
	 * @throws InstructionExecutionException - if there exist any execution error.
	 */
	public void execute() throws InstructionExecutionException {
		this.navigation.scanCurrentPlace();
	}

}
